<?php
require_once 'pages/TMSItemCreationPage.inc';

class TMSCatItemCreationPage extends TMSItemCreationPage {
/**
 * @var TCandyModel
 */	
	protected $_ioc_mtm_model_;
	
	public $ItemRefProperty;
	
	public $NodeProperty;
	
	protected function getItem(){
		$dummy = parent::getItem();
		if ($this->request->node){
			if ($this->NodeProperty){
				if (!$this->ItemRefProperty){
					$nm = $this->NodeProperty;
					$dummy->$nm = $this->request->node;
				} 
			}
		}
		return new TMSPageItem($dummy,$this);
	}
	
	protected function doCreate($data){
		$item = $this->Model->CreateItem($data,$this->creationClass);
		if ($this->request->node && $this->NodeProperty && $this->ItemRefProperty){
			if ($this->MtmModel)
				$this->MtmModel->CreateItem(array(
					$this->ItemRefProperty => $item->Base,
					$this->NodeProperty => $this->request->node
				));
		}
		return $item;
	}
	
}